- /* sdftnhbs.cpp by K.Tsuru */
- // function ID 3327 DRADIX since ver 2.18
- /*****************************************
- SDouble class
- It provides hyperbolic tangent tanh(x)
- using binary splitting method.
- for large x rename "TanBS(x)" since version 2.21
- *****************************************/
- #ifndef SN_H
- #include "sn.h"
- #endif
-
- SDouble TanhBSLx(const SDouble& x){
- if(x.Sign(3327) == 0) return 0.0;
-
- double X = doubleD(x, 0);
- // check the condition "exp(2*x) < DRADIX^DRADIX_EXP_MAX".
- const double xMax = 0.5*(double)DFIGURES*M_LN10*(double)DRADIX_EXP_MAX; // = 301759.17.../2
- if( fabs(X) > xMax){ // exp(x) > D^(DRADIX_EXP_MAX)
- if(x.Sign() > 0) return 1.0;
- return -1.0;
- }
- SDouble r;
- if(x.NetRdxExp() <= 0){ // |x| < DRADIX, tanh x = sinh x/sqrt(1+sinh^2 x)
- r = SinhBS(x);
- r = r*RecSqrt(ONE+r*r);
- } else { //x >= DRADIX
- SDouble x2;
- x2 = DsMult(x, 2); // x2 = x*2
- if(x.Sign() > 0){
- x2 = DReciprocal(ONE + ExpBS(x2)); // x2 = 1/(1+exp(2*x))
- r = ONE - DsMult(x2, 2); // r = 1- 2/(1+exp(2*x))
- } else {
- x2 = DReciprocal(ONE + ExpBS(-x2)); // x2 = 1/(1+exp(-2*x))
- r = DsMult(x2, 2) - ONE; // r = 2/(1+exp(-2*x)) -1
- }
- }
- return r;
- }
sdftnhbs.cpp : last modifiled at 2016/08/29 16:48:07(1,229 bytes)
created at 2017/10/07 10:22:50
The creation time of this html file is 2017/10/07 11:29:39 (Sat Oct 07 11:29:39 2017).